package com.fx.smsclient.JsonSerializer;

import com.google.gson.*;
import com.zx.sms.codec.cmpp.msg.CmppSubmitRequestMessage;

import java.lang.reflect.Type;

// 自定义 GameDate 序列化
public class CmppSubmitRequestMessageSerializer implements JsonSerializer<CmppSubmitRequestMessage> {

    static Gson gson = new GsonBuilder().create();

    @Override
    public JsonElement serialize(CmppSubmitRequestMessage src, Type typeOfSrc, JsonSerializationContext context) {
        JsonElement jsonElement =gson.toJsonTree(src);
        JsonObject jsonObject = (JsonObject) jsonElement;
        jsonObject.remove("msgid");
        jsonObject.addProperty("msgid",src.getMsgid().toString());
        jsonObject.remove("msgContentBytes");
        jsonObject.remove("buffer");
        jsonObject.addProperty("msgContent",src.getMsgContent());
        jsonObject.remove("header");
        jsonObject.addProperty("commandId",Integer.toUnsignedLong(src.getHeader().getCommandId()));
        jsonObject.addProperty("sequenceId",src.getHeader().getSequenceId());
        jsonObject.addProperty("destterminalId",String.join(",",src.getDestterminalId()));
        return jsonObject;
    }
}
